package com.lyx.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.lyx.entity.Menu;
import com.lyx.mapper.MenuMapper;
import com.lyx.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyx.utils.MenuTreeBuilder;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author com.lyx
 * @since 2022-03-02
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Override
    public List<Menu> findMenuTree() {
        //1.先获取所有菜单
        List<Menu> rootMenu = this.baseMapper.selectList(null);
        Collections.sort(rootMenu,Menu.order());
       return MenuTreeBuilder.build(rootMenu);
    }

}
